package com.lxgzhw.student_manager.controller;

import com.lxgzhw.student_manager.dao.StudentDao;
import com.lxgzhw.student_manager.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentDao studentDao;

    @GetMapping("/all")
    public List<Student> all() {
        return studentDao.selectList(null);
    }

    @PostMapping("/add")
    public String add(@RequestBody Student student) {
        System.out.println(student);
        studentDao.insert(student);
        return "ok";
    }

    @GetMapping("/get/{id}")
    public Student get(@PathVariable Integer id) {
        return studentDao.selectById(id);
    }

    @PutMapping("/update")
    public String update(@RequestBody Student student) {
        studentDao.updateById(student);
        return "ok";
    }

    @DeleteMapping("/delete/{id}")
    public String delete(@PathVariable Integer id) {
        studentDao.deleteById(id);
        return "ok";
    }
}
